/**
 * @Description MyAccountController.java
 * @author xu_cc [18724000100@163.com]
 * @date 创建时间：2018年5月18日 下午3:55:09
 */
package com.solution.pc.my.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.solution.admin.customer.entity.CustomerAccountEntity;
import com.solution.admin.customer.service.CustomerAccountService;
import com.solution.common.constants.PublicStatus;
import com.solution.common.constants.PublicStatus.SysCode;
import com.solution.common.controller.BaseController;

/**
 * 我的账号
 * 
 * @author xu_cc
 * @date 创建时间：2018年5月16日 下午5:55:36
 */
@RequestMapping("/pc/my/account")
@Controller("myAccountController")
public class MyAccountController extends BaseController {
	@Autowired
	CustomerAccountService customerAccountService;

	/**
	 * 我的账号
	 * 
	 * @param request
	 * @param response
	 * @param model
	 * @return String
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2018年5月18日 下午3:57:40
	 */
	@RequestMapping("/myAccount")
	public String toPCMyAccountPage(HttpServletRequest request, HttpServletResponse response, Model model) {
		try {
			model.addAttribute("page", "myAccount");
			Long customerId = getCustomerId();
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("customerId", customerId);
			List<CustomerAccountEntity> accountList = customerAccountService.listCustomerAccount(param);
			model.addAttribute("accountList", accountList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "pc/my/account/my_account";
	}
	
	/**
	 * 添加账户
	 * @param request
	 * @param response
	 * @param model
	 * @return String    
	 * @author xu_cc  
	 * @throws Exception exception
	 * @Date 创建时间：2018年5月18日 下午4:23:13
	 */
	@RequestMapping("/addAccount")
	public String toPCAddMyAccountPage(HttpServletRequest request, HttpServletResponse response, Model model) {
		try {
			model.addAttribute("page", "myAccount");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "pc/my/account/add_account";
	}
	
	/**
	 * 添加账户
	 * 
	 * @param request
	 * @param account
	 * @return Map<String,Object>
	 * @author xu_cc
	 * @throws Exception
	 *             exception
	 * @Date 创建时间：2018年5月18日 下午4:03:22
	 */
	@RequestMapping("/doAddAccount")
	@ResponseBody
	public Map<String, Object> doAddAccount(HttpServletRequest request, CustomerAccountEntity account) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			account.setCustomerId(getCustomerId());
			account.setCreater(getUserName());
			account.setCreateTime(new Date());
			account.setModifier(getUserName());
			customerAccountService.saveCustomerAccount(account);
			resultMap.put("resultCode", 1);
			resultMap.put("resultMsg", "账户保存成功");
		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("resultCode", 0);
			resultMap.put("resultMsg", "账户保存失败");
		}
		return resultMap;
	}
}
